← Back to Portfolio

Local LLM – Private RAG

Personal Project | 2026

AI Engineering / Full-Stack Development

PythonFastAPIOllamaPostgreSQLpgvectorDockerJavaScript

I developed a local-first AI application that enables users to query their own documents with open-source language models, without relying on a hosted inference service when using local models.

The system combines semantic document retrieval, configurable model inference and a browser-based interface to provide answers accompanied by relevant source passages.

View GitHub Repository ↗

Document Ingestion & Vector Search

I built a document processing pipeline for PDF, Markdown and plain-text files. The backend extracts text, splits it into overlapping passages and generates embeddings through Ollama.

  • Supports files up to 20 MB.
  • Uses 1,000-character chunks with 200-character overlap.
  • Generates 768-dimensional embeddings using nomic-embed-text.
  • Stores passages and embeddings transactionally in PostgreSQL with pgvector.

Retrieval-Augmented Generation

Rather than changing model weights, I use retrieved document context to ground each response. A question is embedded and matched against indexed passages using cosine distance and an HNSW index.

The five nearest passages are filtered by a configurable distance threshold. If no passage qualifies, the application returns an insufficient-context response without invoking the language model. Otherwise, the retrieved text and recent conversation are sent to the active model.

Source passages and similarity scores are displayed alongside the generated answer, making its supporting evidence easier to inspect.

Hardware-Aware Model Management

I integrated Ollama's HTTP API to manage model downloads, activation and removal directly from the web interface. The application estimates model suitability by comparing model sizes against available system memory and detected NVIDIA GPU memory.

Users can change their active model without restarting the backend. Local models are distinguished from optional cloud models, which require explicit selection.

Backend Architecture & Real-Time Streaming

The FastAPI backend separates ingestion, retrieval, response generation and model management into dedicated modules. PostgreSQL maintains document passages, application settings and conversation history.

Server-Sent Events stream generated text and model installation progress to a lightweight HTML, CSS and JavaScript frontend. Docker Compose manages the vector database, while a Python startup script coordinates initialization.

Privacy, Reliability & Limitations

Local models keep document processing and inference on the user's machine. The default deployment is intended for single-user access through localhost; it does not include authentication. Optional cloud models may send context to a remote service.

The project was tested on Windows with an RTX 3070 laptop GPU (8 GB VRAM) and 15 GB RAM. Hardware ratings are estimates, OCR is not implemented, and the retrieval cutoff was calibrated using a small document set. Source grounding reduces unsupported responses but does not guarantee accuracy.